package components
{
	import components.Circle;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import oboe.core.Controller;
	import oboe.core.Oboe;
	
	public class Background extends Controller
	{
		
		private var type:Class;
		
		public function Background( type:Class ):void
		{
			super();
			this.type = type;
			
			var asset:Sprite = this.getDisplayObject() as Sprite;
			
			var bg:Object = new Sprite();
			with( bg )
			{
				graphics.beginFill( 0xAFAFFF );
				graphics.drawRect(0, 0, Oboe.stage.stageWidth, Oboe.stage.stageHeight);
				graphics.endFill();
				doubleClickEnabled = true;
				addEventListener( MouseEvent.DOUBLE_CLICK, onDoubleClick );
				addCallback( MouseEvent.CLICK, this.signalUp, "setSelected", false );
			}
			
			var btnSave:Object = new Sprite();
			with( btnSave )
			{
				graphics.beginFill( 0x00FF33 );
				graphics.drawCircle( Oboe.stage.stageWidth/2, 50, 10 );
				graphics.endFill();
				addCallback( MouseEvent.CLICK, this.signalUp, "save" );
				buttonMode = true;
			}
			
			asset.addChild(DisplayObject(bg));
			asset.addChild(DisplayObject(btnSave));
		}
		
		private function onDoubleClick( e:MouseEvent ):void
		{
			this.signalUp("addElement", new type({x:e.stageX, y:e.stageY}, true));		
		}
	}
}